<?php 
//彩色标签云插件
class cy_ad extends WP_Widget {

	function cy_ad() {
		$widget_ops = array('description' => '广告小工具，侧边栏宽度300');
		$this->WP_Widget('cy_ad', '&#xE000; 广告', $widget_ops);
	}

	function form($instance) {
		$title = isset($instance['title']) ? $instance['title'] : '广而告之';
		$img1 = isset($instance['img1']) ? $instance['img1'] : '';
		$img2 = isset($instance['img2']) ? $instance['img2'] : '';
		$img3 = isset($instance['img3']) ? $instance['img3'] : '';
		$link1 = isset($instance['link1']) ? $instance['link1'] : '';
		$link2 = isset($instance['link2']) ? $instance['link2'] : '';
		$link3 = isset($instance['link3']) ? $instance['link3'] : '';
		$custom = isset($instance['custom']) ? $instance['custom'] : '';
?>
	<p>
		<label>标题：
			<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
		</label>
	</p>

	<p>
		<label>图片1：
			<input id="<?php echo $this->get_field_id('img1'); ?>" name="<?php echo $this->get_field_name('img1'); ?>" type="text" value="<?php echo $img1; ?>" size="30" />
		</label>
	</p>

	<p>
		<label>链接1：
			<input id="<?php echo $this->get_field_id('link1'); ?>" name="<?php echo $this->get_field_name('link1'); ?>" type="text" value="<?php echo $link1; ?>" size="30" />
		</label>
	</p>

	<p>
		<label>图片2：
			<input id="<?php echo $this->get_field_id('img2'); ?>" name="<?php echo $this->get_field_name('img2'); ?>" type="text" value="<?php echo $img2; ?>" size="30" />
		</label>
	</p>

	<p>
		<label>链接2：
			<input id="<?php echo $this->get_field_id('link2'); ?>" name="<?php echo $this->get_field_name('link2'); ?>" type="text" value="<?php echo $link2; ?>" size="30" />
		</label>
	</p>

	<p>
		<label>图片3：
			<input id="<?php echo $this->get_field_id('img3'); ?>" name="<?php echo $this->get_field_name('img3'); ?>" type="text" value="<?php echo $img3; ?>" size="30" />
		</label>
	</p>

	<p>
		<label>链接3：
			<input id="<?php echo $this->get_field_id('link3'); ?>" name="<?php echo $this->get_field_name('link3'); ?>" type="text" value="<?php echo $link3; ?>" size="30" />
		</label>
	</p>

	<p>
		<label>自定义代码：
			<textarea class="widefat" rows="10" id="<?php echo $this->get_field_id('custom'); ?>" name="<?php echo $this->get_field_name('custom'); ?>"><?php echo $custom; ?></textarea>
		</label>
	</p>
<?php
	}

	function update($new_instance, $old_instance) { return $new_instance; }

	function widget($args, $instance) {
		extract( $args );
		$title = $instance['title'];
		$img1 = $instance['img1'];
		$img2 = $instance['img2'];
		$img3 = $instance['img3'];
		$link1 = $instance['link1'];
		$link2 = $instance['link2'];
		$link3 = $instance['link3'];
		$custom = $instance['custom'];
		echo $before_widget.$before_title.$title.$after_title;
		if($link1&&$img1) echo "<a class=\"lh\" href=\"$link1\" rel=\"external\"><img src=\"$img1\" alt=\"广告\"></a>";
		if($link2&&$img2) echo "<a class=\"lh\" href=\"$link2\" rel=\"external\"><img src=\"$img2\" alt=\"广告\"></a>";
		if($link3&&$img3) echo "<a href=\"$link3\" rel=\"external\"><img src=\"$img3\" alt=\"广告\"></a>";
		if($custom) echo trim($custom);
		echo $after_widget;
	}
}
register_widget('cy_ad');
?>